    /* global FormData visitUrl*/
    /* global getCookie */
    /* global template */
    var oneTypeList = [];
    (function ($) {
        //一级分类
        $.ajax({
            type:'POST',
            url:"/antique/api/sysDict/query_list",
            data: { type:"firstcategory","token":getCookie('token') },
            dataType:"json",
            success:function(result){ 
                if (result.code == 0) {
                    if (result.data && result.data.list && result.data.list.length > 0) {
                        var list = result.data.list;
                        for (var i = 0; i < list.length;i++) { 
                            if(firstCategory == list[i].id)
                                $("#firstCategory").append("<option value='" + list[i].id + "' selected>" + list[i].label + "</option>");
                            else
                                $("#firstCategory").append("<option value='" + list[i].id + "'>" + list[i].label + "</option>");
                        }                        
                    }
                }
            }                   
        });
       
    })(jQuery);

  $("#area-choise").cityPicker({
    showDistrict: false,
    title: "选择城市",
    onChange: function (picker, values, displayValues) {
      var name = displayValues[0] + " " + displayValues[1];
      $("#area").val(name);
    }
  });

  
    $("#uploaderInput").on("change", function(e) {
        var file = e.target.files[0];
        /* global handlePic imageBg*/
        file && handlePic(file,2160,function(res){
            if (res.code == 0){
                $("#image").val(res.data.path);
                imageBg.style.backgroundImage = "url('" + res.data.path + "')";
            } else {
                $.toast(res.message, "cancel");
            }
                
        });
        
    });
    $("#content").keyup(function() {
        var value = $.trim(this.value);
        var descLength = $.trim(this.value).length;
        if (descLength <= 200) { 
            $("#descNumber").html(descLength);
        } else {
            $("#content").val(value.substring(0,200));
        }
    });

    $("#showTooltips").click(function(){        
        var id = $("#shopId").val();
        var name = $("#name").val();
        var area = $("#area").val();
        var mainBusiness = $("#firstCategory").children('option:selected').val();
        var content = $("#content").val();
        var image = $("#image").val();
        var isAgree = $('#weuiAgree').prop("checked");
        if (name == ''){
            $.toast("名称不能为空", "cancel");
            return;
        }
        if ( area == ''){
            $.toast("地区不能为空", "cancel");
            return;
        }
        if ( mainBusiness == ''){
            $.toast("分类不能为空", "cancel");
            return;
        }
        if (typeof image == 'undefined' || image == ''){
            $.toast("请上传图片", "cancel");
            return;
        }
        if(!isAgree && typeof(isUpdateShop)=='undefined'){
            $.toast("请同意卖家服务协议后才能注册店铺", "cancel");
            return;
        }
        var params = {};
        params.id = id;
        params.name = name;
        params.regionShowName = area;
        params.image = image;
        params.token = getCookie('token');
        params.mainBusiness = mainBusiness;
        params.content = content;
       if (id){
        upShop(params);
       } else {
        addShop(params);
       }
    } );

    function addShop(params){
        delete params.id;
        $.ajax({
            type:'POST',
            url:"/antique/api/mallShop/manage/regist_shop",
            data: params,
            dataType:"json",
            success:function(res){
                if (res.code == 0){
                    visitUrl(document.referrer,true);
                    $.toast("成功");
                 } else {
                    $.toast(res.message, "cancel");
                }
                
            }
        });
    }
    function upShop(params){
        $.ajax({
            type:'POST',
            url:"/antique/api/mallShop/manage/update_shop",
            data: params,
            dataType:"json",
            success:function(res){
                if (res.code == 0){
                    visitUrl("/my",true);
                    $.toast("成功");
                 } else {
                    $.toast(res.message, "cancel");
                }
                
            }
        });
    }

    $('#viewAgree').click(function(){
        $("#salerAgreement").popup();
    });

    $('label[for="weuiAgree"]').unbind('click');